package com.wanmait.recruitment.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.recruitment.pojo.Scale;
import com.wanmait.recruitment.service.ConfigService;
import com.wanmait.recruitment.service.ScaleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("manage/scale")
public class ScaleController {

    @Resource
    private ScaleService scaleService;
    @Resource
    private ConfigService configService;
    @RequestMapping("list")
    public  void list(){

    }
    @RequestMapping("listdata")
    public PageInfo<Scale> listdata(Integer pageNum){
        //每页显示条数
        int pageSize;
        try {
            pageSize= Integer.parseInt(configService.getValueByKey("manage_web_menu_count"));
        } catch (NumberFormatException e) {
            pageSize=Integer.parseInt(configService.getDefaultValueByKey("manage_web_menu_count"));
        }
      return scaleService.findPage(pageNum,pageSize);

    }
    @RequestMapping("delete")
    @ResponseBody
    public  void delete(Integer id){
        scaleService.delete(id);

    }
    @RequestMapping("batchDelete")
    @ResponseBody
    public  void batchDelete(String ids){

        scaleService.delete(ids);

    }
    @RequestMapping("update")
    @ResponseBody
    public  void update(Scale scale){
        System.out.println(scale);
        scaleService.update(scale);

    }
    @RequestMapping("insert")
    public  void insert(){

    }

    @PostMapping("addScale")
    public  String addScale(Scale scale){
        System.out.println(scale);
        scaleService.insert(scale);
        return "redirect:/manage/scale/list";
    }


}
